<template>
  <div id="Aside">
    <div class="toggle-button" @click="toggleCollapse">|||</div>
    <el-menu
      class="el-menu-vertical-demo"
      background-color="#313743"
      text-color="#fff"
      active-text-color="#409EFF"
      :unique-opened="true"
      :collapse="isCollapse"
      :collapse-transition="false"
      :router="true"
      :default-active="$route.path"
      >
      <el-submenu
      :index="menuItem.id + ''"
      v-for="menuItem in menuList"
      :key="menuItem.id"
      padding-left="10px"
      >
        <template slot="title" id="title">
          <i :class="iconObj[menuItem.id]"></i>
          <span>{{menuItem.authName}}</span>
        </template>
        <el-menu-item :index="'/' + subItem.path" v-for="subItem in menuItem.children" :key="subItem.id">
          <template slot="title">
          <i class="el-icon-menu"></i>
          <span>{{subItem.authName}}</span>
        </template>
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: 'Aside',
  data () {
    return {
      menuList: [],
      iconObj: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      isCollapse: false
    }
  },
  methods: {
    async getMenuList () {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menuList = res.data
      console.log(res)
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
      this.$emit('toParent', this.isCollapse)
    }
  },
  created () {
    this.getMenuList()
  }
}
</script>

<style Lang="less" scoped>
  .iconfont{
    margin-right: 10px;
  }
  .toggle-button{
    color: #fff;
    line-height: 20px;
    letter-spacing: 0.2em;
    font-size: 10px;
    cursor: pointer;
  }
</style>
